package com.honglang.common.tools;

import java.util.ArrayList;
import java.util.List;

public class Pager {
  private int[] pageSizeList={10,25,50,100,200,300,500};
  private int pageSize=Constants.pageSize;
  private int pageNo=Constants.pageNo;
  private int rowCount=0;
  private int pageCount=0;
  private int startIndex=0;
  private int endIndex=0;
  private int firstIndex=0;
  private int prePageNo=0;
  private int nextPageNo=0;
  private int lastPageNo=0;
  
  private int startPageIndex = 0;
  private int endPageIndex = 0;
  private List<?> resultList;
 
  
  
  public void create(int pageIndexCount){
	  
	 
  }
  
  
  
  public void CreatePager(int pageSize,int pageNo,int pageIndexCount,int rowCount,List<?> resultList){
	  this.pageSize=pageSize;
	  this.pageNo=pageNo;
	  this.rowCount=rowCount;
	  this.resultList=resultList;
	  if(rowCount%pageSize==0){
		  this.pageCount=rowCount/pageSize;
	  }
	  else {
		  this.pageCount=rowCount/pageSize+1;
	  }
	  this.startIndex=pageSize*(pageNo-1);
	  this.endIndex=this.startIndex+resultList.size();
	  this.lastPageNo=this.pageCount;
	  if(this.pageNo>1){
		  this.prePageNo=this.pageNo-1;
	  }
	  if(this.pageNo==this.lastPageNo){
		  this.nextPageNo=this.lastPageNo;
	  }else{
		  this.nextPageNo=this.pageNo+1;
	  }  
	  this.startPageIndex  =  pageIndexCount *(pageNo/pageIndexCount) + 1 ;
	  if(this.startPageIndex != 1){
		  this.startPageIndex--;
	  }
	  this.endPageIndex = startPageIndex + 8;
	  
	  if(endPageIndex > pageCount){
		  this.endPageIndex = pageCount;
	  }
 
  }
  public Object[] getPageSizeIndexs(){
	  List<String> result=new ArrayList<String>(pageSizeList.length);
	  for(int i=0;i<pageSizeList.length;i++){
		  result.add(String.valueOf(pageSizeList[i]));
	  }
	  Object[] indexs=(result.toArray());
	  return indexs;
  }
  
  public Object[] getPageNoIndexs(){
	  List<String> result=new ArrayList<String>(pageCount);
	  for(int i=0;i<pageCount;i++){
		  result.add(String.valueOf(i+1));
	  }
	  Object[] indexs=(result.toArray());
	  return indexs;
  }
public int[] getPageSizeList() {
	return pageSizeList;
}
public void setPageSizeList(int[] pageSizeList) {
	this.pageSizeList = pageSizeList;
}
public int getPageSize() {
	return pageSize;
}
public void setPageSize(int pageSize) {
	this.pageSize = pageSize;
}
public int getPageNo() {
	return pageNo;
}
public void setPageNo(int pageNo) {
	this.pageNo = pageNo;
}
public int getRowCount() {
	return rowCount;
}
public void setRowCount(int rowCount) {
	this.rowCount = rowCount;
}
public int getPageCount() {
	return pageCount;
}
public void setPageCount(int pageCount) {
	this.pageCount = pageCount;
}
public int getStartIndex() {
	return startIndex;
}
public void setStartIndex(int startIndex) {
	this.startIndex = startIndex;
}
public int getEndIndex() {
	return endIndex;
}
public void setEndIndex(int endIndex) {
	this.endIndex = endIndex;
}
public int getFirstIndex() {
	return firstIndex;
}
public void setFirstIndex(int firstIndex) {
	this.firstIndex = firstIndex;
}
public int getPrePageNo() {
	return prePageNo;
}
public void setPrePageNo(int prePageNo) {
	this.prePageNo = prePageNo;
}
public int getNextPageNo() {
	return nextPageNo;
}
public void setNextPageNo(int nextPageNo) {
	this.nextPageNo = nextPageNo;
}
public int getLastPageNo() {
	return lastPageNo;
}
public void setLastPageNo(int lastPageNo) {
	this.lastPageNo = lastPageNo;
}
public List<?> getResultList() {
	return resultList;
}
public void setResultList(List<?> resultList) {
	this.resultList = resultList;
}



public int getStartPageIndex() {
	return startPageIndex;
}



public void setStartPageIndex(int startPageIndex) {
	this.startPageIndex = startPageIndex;
}



public int getEndPageIndex() {
	return endPageIndex;
}



public void setEndPageIndex(int endPageIndex) {
	this.endPageIndex = endPageIndex;
}



}